/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package core;

import java.util.HashMap;
import java.util.LinkedList;
import java.util.List;
import java.util.Map;

/**
 *
 * @author
 */
public abstract class ServerCallBack<K,V> implements IServerCallBack<K, V>{

    private Callback<K,V> callback;

    private List<K> preCallValues= new LinkedList<K>();

    private Map<K,V> map = new HashMap<K, V>();

    public ServerCallBack(Callback<K,V> callback) {
        this.callback = callback;
    }

    public void onError(Exception e) {
        callback.onError(e);
    }

    public void onNewResult(K key,V v) {
        map.put(key,v);
        preCallValues.remove(key);
    }

    public void onFinish() {
        callback.onResult(new Result(map,preCallValues));
    }

    public void onReadHeader(int operation, int numArgs, ProtocolSD protocolSD) {

    }

    public void onReadArgument(byte[] data, ProtocolSD protocolSD) {

    }

    public void onReadArgumentSize(int size, ProtocolSD protocolSD) {

    }

    public void onReadAllArguments(ProtocolSD protocolSD) {

    }

    public void onWriteComplete(ProtocolSD protocolSD) {

    }

    public void onFinishConnect() {

    }

    public void onReadParcialParam(byte[] readedBytes, int offset, int limit) {
        
    }

    
    
}
